<script setup>
    import { ref } from 'vue';
    const props = defineProps(['imgUrl','title','price','id'])
    const emit = defineEmits()

    const x = ref(3)
    const onCut = () => {
        emit('cut',props.id,x.value)
    }
</script>
    
<template>
    <div class="item">
      <img
        :src="imgUrl"
        :alt="title"
      />
      <p class="name">{{ title }}</p>
      <p class="price">{{ price }}.00</p>
      <button @click="onCut">砍价-{{ x }}</button>
    </div>
</template>
    
<style lang="scss" scoped>
.item {
  width: 240px;
  margin-left: 10px;
  padding: 20px 30px;
  transition: all 0.5s;
  margin-bottom: 20px;

  &:nth-child(4n) {
    margin-left: 0;
  }

  &:hover {
    box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.2);
    transform: translate3d(0, -4px, 0);
    cursor: pointer;
  }

  img {
    width: 100%;
  }

  .name {
    font-size: 18px;
    margin-bottom: 10px;
    color: #666;
  }

  .price {
    font-size: 22px;
    color: firebrick;

    &::before {
      content: '¥';
      font-size: 22px;
    }
  }
}
button {
    color: pink;
    background-color: antiquewhite;
}
</style>